import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";
import path from "path";
import createVitePlugins from "./vite/plugins";
import dts from 'vite-plugin-dts'

// https://vitejs.dev/config/
export default () => {
  return defineConfig({
    plugins: [...createVitePlugins(),dts()],
    build: {
      outDir: "dist", //输出文件名称
      lib: {
        entry: path.resolve(__dirname, "./packages/index.ts"), //指定组件编译入口文件
        name: "McProUILibrary",
        fileName: (format) => `index.${format === 'es' ? 'js' : 'js'}`,
      }, //库编译模式配置
      rollupOptions: {
        // 确保外部化处理那些你不想打包进库的依赖
        external: ["vue"],
        output: {
          // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
          globals: {
            vue: "Vue",
          },
        },
      }, // rollup打包配置
    },

    resolve: {
      alias: {
        "@": fileURLToPath(new URL("./packages", import.meta.url)),
      },
    },
  });
};
